package NiuKe;

import java.util.HashMap;

public class KuoHao {
    public boolean isValid (String s) {
        HashMap<Character, Character> map = new HashMap<>(3);
        map.put(')','(');
        map.put(']','[');
        map.put('}','{');
        // write code here
        char[] cs = s.toCharArray();
        if(cs.length / 2 != 0){
            return false;
        }
        char[] stack = new char[cs.length];
        int top = -1;
        boolean flag = true;
        for (char c : cs) {
            if(c == '(' || c == '[' || c == '{'){
                stack[++top] = c;
            }else if(c == ')' || c == ']' || c == '}'){
                if(stack[top] != map.get(c)){
                    flag = false;
                    break;
                }
            }
        }
        return flag;
    }
}
